#pragma once
#include <bondlib/BondMarketStream.h>
#include <bondlib/RealTimeDeal/IRealTimeDealModel.h>

#include <map>

namespace detail {
class ScreenRecordCache {
  typedef DealIndex RecordId;
  typedef int RowId;
  typedef int IndexId;
  typedef MarketStreamInfo Record;
  struct RecordInfo {
    RecordId id;  // record.m_indexID
    IndexId index;
    RowId row;      // 放在表格中的行号
    Record record;  // 成交记录
  };
  typedef std::map<RecordId, RecordInfo> RecordInfoMap;
  typedef std::map<RowId, RecordId> RecordIdMap;
  RecordInfoMap m_records;
  RecordIdMap m_rows;

 private:
  ScreenRecordCache& operator=(const ScreenRecordCache& cache);
  ScreenRecordCache(const ScreenRecordCache& cache);

 public:
  ScreenRecordCache();
  void Clear();
  void AddRecord(const RecordId& id, int index, int row, const Record& record);
  bool GetRecord(const RecordId& id, Record& record);
  bool IsExistById(const RecordId& id) const;
  bool GetIdByRow(int row, RecordId& id) const;
  bool GetRowById(const RecordId& id, int& row) const;
};
}  // namespace detail
